package com.xbongbong.sso.model.impl;

import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.sso.domain.dao.OauthStepDao;
import com.xbongbong.sso.domain.entity.OauthStepEntity;
import com.xbongbong.sso.model.OauthStepModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author bomfish
 */
@Service("oauthStepModel")
public class OauthStepModelImpl implements OauthStepModel {
    @Resource
    private OauthStepDao oauthStepDao;

    @Override
    public Long insert(OauthStepEntity entity) {
        return oauthStepDao.insert(entity);
    }

    @Override
    public void insertBatch(List<OauthStepEntity> list) {
        oauthStepDao.insertBatch(list);
    }

    @Override
    public List<OauthStepEntity> findEntities(Map<String, Object> param) {
        return oauthStepDao.findEntities(param);
    }

    @Override
    public Integer getEntityCount(Map<String, Object> param) {
        return oauthStepDao.getEntitiesCount(param);
    }

    @Override
    public void update(OauthStepEntity entity) {
        oauthStepDao.update(entity);
    }

    @Override
    public OauthStepEntity getByKey(Long key, String corpid) {
        return oauthStepDao.getByKey(key, corpid);
    }

    @Override
    public OauthStepEntity getEntity(String corpid, Long connectorId, Integer stepType) {
        return oauthStepDao.getEntity(corpid, connectorId, stepType);
    }

    @Override
    public List<OauthStepEntity> getByConnectorId(String corpid, Long connectorId, Integer enable) {
        Map<String, Object> param = new HashMap<>();
        param.put("corpid", corpid);
        param.put("connectorId", connectorId);
        param.put("enable", enable);
        param.put("del", DelEnum.NORMAL.getDel());
        param.put("orderByStr", "step_type");
        return findEntities(param);
    }
}
